package com.yingli.network.jiemian;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.yingli.network.R;

public class InterfaceActivity extends AppCompatActivity {
    //定义按钮，为后面指定
    private TextView a_circle;
    private TextView a_drawing;
    private TextView a_information;
    private TextView a_mine;
    //定义需要获取访问的类
    private Interface b_anInterface;//圈子界面
    private Drawing b_Drawing;//画板 界面
    private Information b_Information;//消息界面
    private Mine b_Mine;//我的 界面

    private FragmentManager manager;
    private FragmentTransaction transaction;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_liebiao);
        //操作Fragment，需要manager对象去操作每个fragment，获取manager对象
        manager = getSupportFragmentManager();
        //开始事务管理
        transaction = manager.beginTransaction();
        //实例化每个Fragment片段
        b_anInterface = new Interface();
        b_Drawing = new Drawing();
        b_Information = new Information();
        b_Mine = new Mine();
        //事务添加Fragment，把Fragment添加到容器（FrameLayout）中
        transaction.add(R.id.fl_container,b_anInterface);
        //提交事务
        transaction.commit();
        //按钮的实例
        a_circle = findViewById(R.id.circle);
        a_drawing = findViewById(R.id.drawing);
        a_information = findViewById(R.id.information);
        a_mine = findViewById(R.id.mine);
        //按钮实现跳转
        a_circle.setOnClickListener(v -> {
            transaction = manager.beginTransaction();//开始管理事务
            transaction.replace(R.id.fl_container,b_anInterface);
            transaction.commit();//提交事务
        });
        a_drawing.setOnClickListener(v -> {
            transaction = manager.beginTransaction();
            transaction.replace(R.id.fl_container,b_Drawing);
            transaction.commit();
        });
        a_information.setOnClickListener(v -> {
            transaction = manager.beginTransaction();
            transaction.replace(R.id.fl_container,b_Information);
            transaction.commit();
        });
        a_mine.setOnClickListener(v -> {
            transaction = manager.beginTransaction();
            transaction.replace(R.id.fl_container,b_Mine);
            transaction.commit();
        });
    }
}
